﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.UI;
using TableTools;
using TableTools.Designer;

namespace HYRElectric.PowerSystem
{
	internal class MaterialListOutput
	{
		public MaterialListOutput(ExternalCommandData commandData)
		{
			this.m_cmdData = commandData;
		}

		public void Drawing(string strSwitchbox, string strLoop, double dPower, List<MaterialInfo> lstInfo, ref string message)
		{
			int rowCount = lstInfo.Count + 1;
			int colCount = 7;
			List<CellInfo> allCellInfo = this.GetAllCellInfo(strSwitchbox, strLoop, dPower, lstInfo);
			TableInterface.DrawGeneralTable(this.m_cmdData, rowCount, colCount, allCellInfo, ref message, null, null, true);
		}

		private List<CellInfo> GetAllCellInfo(string strSwitchbox, string strLoop, double dPower, List<MaterialInfo> lstInfo)
		{
			List<CellInfo> list = new List<CellInfo>();
			int count = lstInfo.Count;
			list.Add(new CellInfo(0, 0, 0, 0, "配电箱编号", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(0, 0, 1, 1, "回路编号", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(0, 0, 2, 2, "回路功率", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(0, 0, 3, 3, "名称", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(0, 0, 4, 4, "规格", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(0, 0, 5, 5, "数量", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(0, 0, 6, 6, "单位", CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(1, count + 1, 0, 0, strSwitchbox, CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(1, count + 1, 1, 1, strLoop, CellInfo.CellInfoType.CIT_Text));
			list.Add(new CellInfo(1, count + 1, 2, 2, dPower.ToString("0.0"), CellInfo.CellInfoType.CIT_Text));
			for (int i = 0; i < lstInfo.Count; i++)
			{
				MaterialInfo materialInfo = lstInfo[i];
				list.Add(new CellInfo(i + 1, i + 1, 3, 3, materialInfo.strName, CellInfo.CellInfoType.CIT_Text));
				list.Add(new CellInfo(i + 1, i + 1, 4, 4, materialInfo.strSpec, CellInfo.CellInfoType.CIT_Text));
				if (materialInfo.strUnit.CompareTo("米") == 0)
				{
					list.Add(new CellInfo(i + 1, i + 1, 5, 5, materialInfo.dLength.ToString("0.0"), CellInfo.CellInfoType.CIT_Text));
				}
				else
				{
					list.Add(new CellInfo(i + 1, i + 1, 5, 5, materialInfo.nCount.ToString(), CellInfo.CellInfoType.CIT_Text));
				}
				list.Add(new CellInfo(i + 1, i + 1, 6, 6, materialInfo.strUnit, CellInfo.CellInfoType.CIT_Text));
			}
			return list;
		}

		private ExternalCommandData m_cmdData;
	}
}
